<%--
  Created by IntelliJ IDEA.
  User: 22179
  Date: 2025/3/3
  Time: 17:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/index_work.css">
    <title>Title</title>
    <style>
        table{
            border: 1px solid black;
            width: 800px;
            border-collapse: collapse;
            cellpadding:"0px" ;
            cellspacing:"0px";
        }
        table td, table th { /* 给所有的td和th加上边框 */
            border: 1px solid black;
            padding: 5px; /* 可以根据需要调整 */
        }
    </style>
    <script>
        var msg="${msg}";
       if(msg!=null && msg!=""){
           alert(msg);
       }


    </script>
</head>
<body>
      <h1>欢迎${name}登录!</h1>
      <button onclick="addbook()">添加图书</button>
      <a href="/User/inquire">用户管理</a><br>
      <form action="/Book/inquire" method="post">
          <input value="/Book/inquire" hidden>
           书名:<input type="text" name="bname" id="bname" value="${bname}">
           作者:<input type="text" name="author" id="author" value="${author}">
          <button>查询图书</button>
      </form>
      <table>
          <tr>
              <td>编号</td>
              <td>书名</td>
              <td>作者</td>
              <td>数量</td>
              <td>价格</td>
              <td>操作</td>
          </tr>
            <c:forEach items="${page.content}" var="book" >
                <tr>
                <td>${book.id}</td>
                <td>${book.name}</td>
                <td>${book.author}</td>
                <td>${book.bsum}</td>
                <td>${book.price}</td>
                 <td>
                     <button onclick="upbook(${book.id})">修改</button>
                     <button onclick="delbook(${book.id})">删除</button>
                 </td>
                </tr>
            </c:forEach>

      </table>
      <button onclick="show(1)">首页</button>
      <button onclick="le(${page.currentPage})">上一页</button>
      <button>第${page.currentPage}页/共${page.pageTotal}页</button>
      <button onclick="ri(${page.currentPage},${page.pageTotal})">下一页</button>
      <button onclick="show(${page.pageTotal})">尾页</button>
      共${page.recordTotal}条
<script>
    var  bname = $("#bname").val();
    var  author = $("#author").val();

    function ri(pagesize,pagetotal) {
        if(pagesize==pagetotal||typeof (pagesize)=="undefined"){
            alert("已经是最后一页了");
        }else{
            if(typeof (bname)=="undefined"){
                bname="";
            }
            if(typeof (author)=="undefined"){
                author="";
            }
            location.href="/Book/inquire?pagesize="+(pagesize+1)+"&bname="+bname+"&author"+author;
        }
    }
    function  le(pagesize){
        if(pagesize==1||typeof (pagesize)=="undefined"){
            alert("已经是第一页了");
        }else{
            if(typeof (bname)=="undefined"){
                bname="";
            }
            if(typeof (author)=="undefined"){
                author="";
            }
            location.href="/Book/inquire?pagesize="+(pagesize-1)+"&bname="+bname+"&author"+author;
        }
    }
    function show(pagesize){
        if(typeof (bname)=="undefined"){
            bname="";
        }
        if(typeof (author)=="undefined"){
            author="";
        }
        location.href="/Book/inquire?pagesize="+pagesize+"&bname="+bname+"&author"+author;

    }
    function addbook() {
        location.href="/addbook.jsp";
    }
    function upbook(id) {
        location.href="/Book/upbook?id="+id;
    }
    function delbook(id) {
        if(confirm("确定删除吗？")){
        }
        location.href="/Book/delbook?id="+id;
    }


</script>



</body>
</html>
